<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>新增需求</title>
	<link rel="icon" href="../../img/icon.png" type="image/x-icon"/>
	<link rel="stylesheet" type="text/css" href="../../css/mui.css"/>
	<link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
	<link rel="stylesheet" type="text/css" href="../../css/app.css"/>
</head>
<body>
<!-- 顶部菜单 -->
<ul id="top">
	<!-- <li class="addBug back" onclick="mui.back();">返回</li> -->
	<li class="addBug back" onclick="jumpToIndexPubSel()">返回</li>
	<li class="addBug">新增需求</li>
	<li class="addBug back">&nbsp;</li>
</ul>
<!-- 主体 -->
<div style="height: 50px;"></div>
<div class="form">
	<h2>新增需求</h2>
	<input type="text" id="name" placeholder="需求名称" value=""/>
	<textarea placeholder="需求描述" id="detail"></textarea>
	<select id="alm">
		<!-- <option value ="1"></option> -->
	</select>
	<input type="button"  value="保存" onclick="setNeedAdd()"/>
</div>
<div style="height: 50px;"></div>
<!-- 底部菜单 -->
<ul id="foot">
	<li onclick="jumpToIndex()">BUG</li>
	<li class="noclick" onclick="jumpToHistory()">历史</li>
	<li class="noclick" onclick="jumpToMore()">更多</li>
	<li class="noclick" onclick="jumpToMy()">我的</li>
</ul>
</body>
</html>


<script type="text/javascript" src="../../js/mui.min.js"></script>
<script type="text/javascript" src="../../js/app.js"></script>
<script type="text/javascript">
	var domain = getDomain();
	var token = getAdminToken();
	(function($, owner) {
		getAdminList();
	}(mui, window.app = {}));
	//获取人员
	function getAdminList(){
		mui.ajax(domain+'/app/admin/index',{
			data:{
				token: token
			},
			dataType:'json',//服务器返回json格式数据
			type:'post',//HTTP请求类型
			timeout:10000,//超时时间设置为10秒；
			// headers:{'Content-Type':'application/json'},
			headers:{'Content-Type':'application/x-www-form-urlencoded'}, 
			success:function(res){
				console.log(res); 
				if (res.code!=0) {
					mui.toast(res.msg+'！',{ 
						duration:'long', type:'div',
					});
					return
				}
				var datalist = res.data;
				var i, list = '';
				list += '<option value ="0">负责人</option>';
				for (i=0;i<datalist.length;i++) {
					list += '<option value ="'+datalist[i].adminId+'">';
					list += datalist[i].adminName;
					list += '</option>';
				}
				mui("#alm")[0].innerHTML = list;
			},
			error:function(xhr,type,errorThrown){
				// console.log('网络错误');
				mui.toast(xhr+type+'网络错误！',{
					duration:'long', type:'div',
				});
			}
		});	
	}
	//新增
	function setNeedAdd(){
		var name = mui("#name")[0].value;
		var detail = mui("#detail")[0].value;
		var alm = mui("#alm")[0].value;
		if (!name) {
			mui.toast('需求名称未填写！',{ 
				duration:'long', type:'div',
			});
			return
		}
		mui.ajax(domain+'/app/bug/add',{
			data:{
				token: token,
				name: name,
				detail: detail,
				genre: 1,
				alm: alm
			},
			dataType:'json',//服务器返回json格式数据
			type:'post',//HTTP请求类型
			timeout:10000,//超时时间设置为10秒；
			// headers:{'Content-Type':'application/json'},
			headers:{'Content-Type':'application/x-www-form-urlencoded'}, 
			success:function(res){
				console.log(res); 
				if (res.code!=0) {
					mui.toast(res.msg+'！',{ 
						duration:'long', type:'div',
					});
					return
				}
				//成功提示
				mui.toast('保存成功！',{ 
					duration:'long', type:'div',
				});
				//页面跳转
				setTimeout(function(){
					jumpToIndex();
				}, 2000);
			},
			error:function(xhr,type,errorThrown){
				// console.log('网络错误');
				mui.toast(xhr+type+'网络错误！',{
					duration:'long', type:'div',
				});
			}
		});	
	}
</script>